package other.nowcoder.easy;

import java.util.Scanner;

/**
 * @author bruin_du
 * @description 美国节日
 * https://www.nowcoder.com/questionTerminal/d95d98a2f96e49078cd7df84ba0c9d79
 * @date 2022/5/30 20:47
 **/
public class AmericanFestival {
    private static final int[] arr = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};

    private static boolean isLeapYear(int year) {
        return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
    }

    private static int countDays(int year,int month,int day) {
        int days = day;
        for (int i = 0; i < month - 1; i++) {
            days += arr[i];
        }
        if(month > 2 && isLeapYear(year)){
            days++;
        }
        return days;
    }

    private static int monthFirstWeek(int year,int month,int day) {
        year = year - 1;
        int week =  (year + year/ 4 - year/ 100 + year/ 400 + countDays(year, month, day)) % 7;
        if(week == 0){
            week = 7;
        }
        return week;
    }

    private static int fromToWeek(int fromWeek,int n,int toWeek) {
        return 1 + 7 * (n - 1) + (7 - fromWeek + toWeek) % 7;
    }

    private static int toFromWeek(int fromWeek){
        return 32 - (fromWeek == 1 ? 7  : fromWeek - 1);
    }

    public static void main(String[] args) {
        /**
         * * 1月1日：元旦
         * * 1月的第三个星期一：马丁·路德·金纪念日
         * * 2月的第三个星期一：总统节
         * * 5月的最后一个星期一：阵亡将士纪念日
         * * 7月4日：美国国庆
         * * 9月的第一个星期一：劳动节
         * * 11月的第四个星期四：感恩节
         * * 12月25日：圣诞节
         */
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int year = in.nextInt();
            System.out.printf("%d-%02d-%02d\n",year,1,1);

            int week = monthFirstWeek(year,1,1);
            System.out.printf("%d-%02d-%02d\n",year,1,fromToWeek(week,3,1));

            week = monthFirstWeek(year,2,1);
            System.out.printf("%d-%02d-%02d\n",year,2,fromToWeek(week,3,1));

            week = monthFirstWeek(year,6,1);
            System.out.printf("%d-%02d-%02d\n",year,5,toFromWeek(week));

            System.out.printf("%d-%02d-%02d\n",year,7,4);

            week = monthFirstWeek(year,9,1);
            System.out.printf("%d-%02d-%02d\n",year,9,fromToWeek(week,1,1));

            week = monthFirstWeek(year,11,1);
            System.out.printf("%d-%02d-%02d\n",year,11,fromToWeek(week,4,4));

            System.out.printf("%d-%02d-%02d\n",year,12,25);
        }
    }
}
